<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>
        <ui:composition template="./../../Template/generalTemplate.xhtml">
            <ui:define name="content">
                <h:form id="form">
                    <p:panel id="salesQuotationList" header="Sales Quotation List" style="height:495px;">

                        <div style="margin-top:20px;margin-left:50px;margin-right:50px;margin-bottom:20px;"> 
                            <p:dataTable id="quotation" dynamic="true" emptyMessage="No Sales Quotation has been Created" value="#{deleteSalesQuotationManagedBean.getSalesQuotations()}" var ="o" paginator="true" rows="6">

                                <p:column filterBy="#{o.id}" filterMatchMode="contains" headerText="Sales Quotation ID"
                                          style="width:200px;">
                                    #{o.id}
                                </p:column>

                                <p:column filterBy="#{o.company.name}" filterMatchMode="contains" headerText="Client">
                                    #{o.company.name}
                                </p:column> 

                                <p:column filterBy="#{o.processedBy}" filterMatchMode="contains" headerText="Processed By">
                                    #{o.processedBy}
                                </p:column> 
                                
                                <p:column filterBy="#{o.used}" filterMatchMode="contains" headerText="Used by Sales Order">
                                    #{o.used}
                                </p:column> 

                                <p:column style="width:80px;text-align: center;">
                                    <f:facet name="header">Action</f:facet>

                                    <p:commandButton update=":form:display" oncomplete="viewDetailsDialog.show()" image="ui-icon ui-icon-search" title="View" actionListener="#{deleteSalesQuotationManagedBean.viewProcessing}">
                                        <f:attribute name="ViewQuotation" value="#{o}"/>
                                    </p:commandButton>

                                    <p:commandButton update=":form:display" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete" style="margin-left: 10px;">  
                                        <f:setPropertyActionListener value="#{o}" target="#{deleteSalesQuotationManagedBean.selectedQuotation}" />  
                                    </p:commandButton>

                                </p:column>        
                            </p:dataTable>
                        </div>


                        <p:dialog header="Quotation Detail" widgetVar="viewDetailsDialog" resizable="false" id="viewDetails" showEffect="fade" hideEffect="explode" modal="true" width="1000">  

                            <p:outputPanel id="display">
                                <h:panelGrid id="dis" columns="2" cellpadding="0" >  
                                    <h:outputText value="Quotation ID" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteSalesQuotationManagedBean.temp.id}" style="font-weight:bold"/>  
                                    </h:panelGroup>  

                                    <h:outputText value="Company" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteSalesQuotationManagedBean.temp.company.name}" style="font-weight:bold"/>  
                                    </h:panelGroup> 

                                    <h:outputText value="Raise Date" /> 
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteSalesQuotationManagedBean.temp.raiseDate}" style="font-weight:bold">  
                                            <f:convertDateTime pattern="dd-MM-yyyy" />
                                        </h:outputText>
                                    </h:panelGroup> 

                                    <h:outputText value="Lead Time (days)" /> 
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteSalesQuotationManagedBean.temp.leadTime}" style="font-weight:bold"/>
                                    </h:panelGroup>
                                    
                                    <h:outputText value="Valid Until" /> 
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteSalesQuotationManagedBean.temp.validUntil}" style="font-weight:bold">  
                                            <f:convertDateTime pattern="dd-MM-yyyy" />
                                        </h:outputText>
                                    </h:panelGroup>  

                                    <h:outputText value="User Discount" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteSalesQuotationManagedBean.temp.userDiscount}" style="font-weight:bold"/>  
                                    </h:panelGroup>

                                    <h:outputText value="Total Price" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{deleteSalesQuotationManagedBean.temp.totalPrice}" style="font-weight:bold"/>  
                                    </h:panelGroup> 
                                </h:panelGrid>

                                <p:dataTable id="lineItemDetail" dynamic="true" emptyMessage="No Line Items are founded" value="#{deleteSalesQuotationManagedBean.temp.quotationLineItems}" var ="l" >

                                    <p:column  >
                                        <f:facet name="header">Product Name</f:facet>
                                        #{l.product.productName}
                                    </p:column>

                                    <p:column>
                                        <f:facet name="header">Quantity</f:facet>
                                        #{l.quantity}
                                    </p:column>
                                    
                                    <p:column>
                                        <f:facet name="header">Original Unit Price</f:facet>
                                        <h:outputText value="#{l.product.basePrice}" />
                                    </p:column>
                                    
                                    <p:column>
                                        <f:facet name="header">Promotional Price</f:facet>
                                        <h:outputText value="#{l.product.promotionPrice}" />
                                    </p:column>
                                    
                                    <p:column>
                                        <f:facet name="header">Discount</f:facet>
                                        <h:outputText value="#{l.discount}" />
                                    </p:column>
                                    
                                    <p:column>
                                        <f:facet name="header">Unit Price</f:facet>
                                        #{l.price}
                                    </p:column> 
                                    
                                    <p:column>
                                        <f:facet name="header">Subtotal</f:facet>
                                        <h:outputText value="#{l.cumAmount}" />
                                    </p:column>
                                </p:dataTable>

                            </p:outputPanel>
                        </p:dialog>


                        <p:confirmDialog message="Are you sure to delete?" 
                                         showEffect="explode" hideEffect="explode"  
                                         header="Confirm" severity="alert" widgetVar="confirmation">  

                            <p:commandButton value="Confirm" update="quotation" actionListener="#{deleteSalesQuotationManagedBean.deleteSalesQuotation}" oncomplete="confirmation.hide()">  

                                <f:attribute name="deleteQuotation" value="#{deleteSalesQuotationManagedBean.selectedQuotation.id}" />
                            </p:commandButton>
                            <p:commandButton value="Cancel" onclick="confirmation.hide()" type="button" />  

                        </p:confirmDialog>

                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
